package com.msconfig.mvp.view.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.geo.msconfig.R;
import com.msconfig.event.WifiModelDialogDismissEvent;

import org.greenrobot.eventbus.EventBus;

import static com.msconfig.mvp.view.fragment.SetupWifiFragment.WIFIMODELNAME;

public class SetupWifiModelDialogActivity extends Activity implements View.OnClickListener{
    private RelativeLayout rlHotspot;
    private TextView tvHotspot;
    private CheckBox cbHotspot;
    private RelativeLayout rlWifiHotspot;
    private TextView tvWifiHotspot;
    private CheckBox cbWifiHotspot;
    private RelativeLayout rlCentralNodeWifi;
    private TextView tvCentralNodeWifi;
    private CheckBox cbCentralNodeWifi;
    private RelativeLayout rlCentralNode4G;
    private TextView tvCentralNode4G;
    private CheckBox cbCentralNode4G;
    private RelativeLayout rlChildNode;
    private TextView tvChildNode;
    private CheckBox cbChildNode;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_activity_setup_wifi_model_dialog);
        initView();
        initData();
    }

    private void initData() {
        //选中已选择的
        Intent intent=getIntent();
        String wifiModel=intent.getStringExtra(WIFIMODELNAME);
        if(wifiModel.equals(getResources().getString(R.string.hotspot))){
            cbHotspot.setChecked(true);
        }else if(wifiModel.equals(getResources().getString(R.string.wifi_hotspot))){
            cbWifiHotspot.setChecked(true);
        }else if(wifiModel.equals(getResources().getString(R.string.central_node_wifi))){
            cbCentralNodeWifi.setChecked(true);
        }else if(wifiModel.equals(getResources().getString(R.string.central_node_4G))){
            cbCentralNode4G.setChecked(true);
        }else if(wifiModel.equals(getResources().getString(R.string.child_node))){
            cbChildNode.setChecked(true);
        }else{
            cbHotspot.setChecked(true);
        }
    }

    private void initView() {
        rlHotspot = (RelativeLayout)findViewById( R.id.rl_hotspot );
        cbHotspot = (CheckBox)findViewById( R.id.cb_hotspot );
        rlWifiHotspot = (RelativeLayout)findViewById( R.id.rl_wifi_hotspot );
        cbWifiHotspot = (CheckBox)findViewById( R.id.cb_wifi_hotspot );
        rlCentralNodeWifi = (RelativeLayout)findViewById( R.id.rl_central_node_wifi );
        cbCentralNodeWifi = (CheckBox)findViewById( R.id.cb_central_node_wifi );
        rlCentralNode4G = (RelativeLayout)findViewById( R.id.rl_central_node_4G );
        cbCentralNode4G = (CheckBox)findViewById( R.id.cb_central_node_4G );
        rlChildNode = (RelativeLayout)findViewById( R.id.rl_child_node );
        cbChildNode = (CheckBox)findViewById( R.id.cb_child_node );

        tvHotspot=findViewById(R.id.tv_hotspot);
        tvWifiHotspot=findViewById(R.id.tv_wifi_hotspot);
        tvCentralNodeWifi=findViewById(R.id.tv_central_node_wifi);
        tvCentralNode4G=findViewById(R.id.tv_central_node_4G);
        tvChildNode=findViewById(R.id.tv_child_node);

        rlHotspot.setOnClickListener(this);
        rlWifiHotspot.setOnClickListener(this);
        rlCentralNodeWifi.setOnClickListener(this);
        rlCentralNode4G.setOnClickListener(this);
        rlChildNode.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        if(v==rlHotspot){
            //更新参数设置页面
            EventBus.getDefault().post(new WifiModelDialogDismissEvent(tvHotspot.getText().toString().trim()));
            finish();
        }else if(v==rlWifiHotspot){
            EventBus.getDefault().post(new WifiModelDialogDismissEvent(tvWifiHotspot.getText().toString().trim()));
            finish();
        }else if(v==rlCentralNodeWifi){
            EventBus.getDefault().post(new WifiModelDialogDismissEvent(tvCentralNodeWifi.getText().toString().trim()));
            finish();
        }else if(v==rlCentralNode4G){
            EventBus.getDefault().post(new WifiModelDialogDismissEvent(tvCentralNode4G.getText().toString().trim()));
            finish();
        }else if(v==rlChildNode){
            EventBus.getDefault().post(new WifiModelDialogDismissEvent(tvChildNode.getText().toString().trim()));
            finish();
        }
    }
}
